package emulator.unittest.assembler;


import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

import emulator.assembler.SymbolTableEntry;

public class SymbolTableEntryTest {

	@Before
	public void setUp() throws Exception {
	}
	
	@Test
	public void testInvalidSymbolsFromString()
	{
		assertNull(SymbolTableEntry.createFromString(""));
		assertNull(SymbolTableEntry.createFromString(";0 null A Zero DATA"));
		assertNull(SymbolTableEntry.createFromString("6767"));
		assertNull(SymbolTableEntry.createFromString(";c369           \'error\'                                 DATA"));

	}

	@Test
	public void testShortSymbolsFromString()
	{
		checkSymbolFromString("A000 modulram",
							  0xa000, "modulram", null, SymbolTableEntry.SYMBOL_TYPE_CODE);
	}

	@Test
	public void testValidSymbolsFromString()
	{
		checkSymbolFromString("c000    -       Basic Restart Vectors                   WORD",
							  0xc000, null, "Basic Restart Vectors", SymbolTableEntry.SYMBOL_TYPE_WORD);
	}

	@Test
	public void testCodeDefaultSymbolsFromString()
	{
		checkSymbolFromString("c000    -       Basic Restart Vectors",
							  0xc000, null, "Basic Restart Vectors", SymbolTableEntry.SYMBOL_TYPE_CODE);
	}
	
	@Test
	public void testCC65LabelFromString()
	{
		checkSymbolFromString("al 00FFA5 .ACPTR",
							  0xFFA5, "ACPTR", null, SymbolTableEntry.SYMBOL_TYPE_UNKNOWN);
	}
	
	private void checkSymbolFromString(String string, int address, String label,
			String remark, int symbol_type) {
		SymbolTableEntry entry = SymbolTableEntry.createFromString(string);
		assertNotNull(entry);
		assertEquals(address, entry.getAddress());
		assertEquals(label, entry.getLabel());
		assertEquals(remark, entry.getRemark());
		assertEquals(symbol_type, entry.getType());
	}

}
